var langs = new Object();
langs["c"] = "c";
langs["cpp"] = "c++";
langs["cs"] = "c#";
langs["css"] = "css";
langs["basic"] = "basic";
langs["html"] = "html";
langs["java"] = "java";
langs["js"] = "javascript";
langs["pas"] = "pascal";
langs["perl"] = "perl";
langs["php"] = "php";
langs["python"] = "python";
langs["ruby"] = "ruby";
langs["sql"] = "sql";
langs["vb"] = "visual basic";
langs["xml"] = "xml";
langs["none"] = "plain text";

var hidden = false;
function toggle_menu(duration) {
    if(!duration) {
        var duration = .4;
    }
    if(hidden) {
        Effect.Appear('languages', {duration:duration});
    } else {
        Effect.Fade('languages', {duration:duration});
    }
    hidden = !hidden;
}

function change_lang(lang, notoggle) {

//    if(!notoggle) {
//        toggle_menu();
//    }

    full_name = langs[lang];

    if($("current_lang_text").innerHTML == full_name) {
        return;
    }

    if(!notoggle) {
        new Ajax.Request('/post_lang', 
        {
            method:'post',
            parameters: {lang:lang, id:id},
            onFailure: function(transport) {
                alert("post failed");
            }
        });
    }
    $("current_lang_text").innerHTML = full_name;

    if(lang == "none") {
        editAreaLoader.execCommand('the_input', 'change_highlight', false);
    } else {
        editAreaLoader.execCommand('the_input', 'change_highlight', true);
        editAreaLoader.execCommand('the_input', 'change_syntax', lang);
    }
}
